/**
 *
 */
package com.angel.io.processors.runners.transformers.impl;

import java.io.InputStream;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.angel.io.descriptor.ExportedFileDescriptor;
import com.angel.io.exceptions.InvalidRowDataException;
import com.angel.io.processors.runners.exports.ExportProcessorRunner;
import com.angel.io.processors.runners.imports.ImportProcessorRunner;
import com.angel.io.processors.runners.transformers.TransformerProcessorRunner;

/**
 * @author William
 *
 */
public class BasicTransformerProcessorRunner implements TransformerProcessorRunner{

	private static final Logger LOGGER = Logger.getLogger(BasicTransformerProcessorRunner.class);

	private ImportProcessorRunner importProcessorRunner;
	
	private ExportProcessorRunner exportProcessorRunner;
	
	
	public BasicTransformerProcessorRunner(ImportProcessorRunner importProcessorRunner, ExportProcessorRunner exportProcessorRunner){
		super();
		this.setExportProcessorRunner(exportProcessorRunner);
		this.setImportProcessorRunner(importProcessorRunner);
	}


	public ExportedFileDescriptor runProcess(InputStream inputStream, Integer... pages) throws InvalidRowDataException {
		long beginMillis = System.currentTimeMillis();
		LOGGER.info("Beginning transformer process at [" + new Date() + "].");
		List<?> _list = this.getImportProcessorRunner().runProcess(inputStream, pages);

		ExportedFileDescriptor exportedFileDescriptor = this.getExportProcessorRunner().runProcess(_list);
		long endMillis = System.currentTimeMillis();
		LOGGER.info("Ended transformer process at [" + new Date() + "]. It ended in [" + ((endMillis - beginMillis ) / 1000 ) + "] seconds.");
		return exportedFileDescriptor;
	}


	/**
	 * @return the importProcessorRunner
	 */
	protected ImportProcessorRunner getImportProcessorRunner() {
		return importProcessorRunner;
	}


	/**
	 * @param importProcessorRunner the importProcessorRunner to set
	 */
	protected void setImportProcessorRunner(
			ImportProcessorRunner importProcessorRunner) {
		this.importProcessorRunner = importProcessorRunner;
	}


	/**
	 * @return the exportProcessorRunner
	 */
	protected ExportProcessorRunner getExportProcessorRunner() {
		return exportProcessorRunner;
	}


	/**
	 * @param exportProcessorRunner the exportProcessorRunner to set
	 */
	protected void setExportProcessorRunner(
			ExportProcessorRunner exportProcessorRunner) {
		this.exportProcessorRunner = exportProcessorRunner;
	}
}
